/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.jdbc.dataAccess;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

/******************************************************************************
 * 
 * @autor   robert.baron
 * @since       02-abr-2013
 * 
 *******************************************************************************/
public class DatabaseFactory {
      
      
      private static String OracleClass = "com.jdbc.dataAccess.Oracle.OracleDatabase";
      
      public static Database createDatabase(String connectionString, int database) throws ClassNotFoundException, NoSuchMethodException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException{
           
            Database db  =  null;
           switch (database){
                 
                 case Database.OracleDatabase:
                       
                        Constructor c = Class.forName(OracleClass).getConstructor(String.class);
                        db = (Database)c.newInstance(connectionString);
                  break;
                       
                 default:
                       throw new  IllegalArgumentException("Database must be correctly set.");
                       
                  
            }
           return db;
      }
      
      public static Database createDatabase(ConnectionSettings connSetttings, int database) throws ClassNotFoundException, NoSuchMethodException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException{
           
            Database db  =  null;
           switch (database){
                 
                 case Database.OracleDatabase:
                       
                        Constructor c = Class.forName(OracleClass).getConstructor(ConnectionSettings.class);
                        db = (Database)c.newInstance(connSetttings);
                  break;
                       
                 default:
                       throw new  IllegalArgumentException("Database must be correctly set.");
                       
                  
            }
           return db;
      }
}
